package leetcode101.bit_operation;

/**
 * @author Synhard
 * @version 1.0
 * @Class Code2
 * @Description 190. Reverse Bits (Easy)
 * 给定一个十进制整数，输出它在二进制下的翻转结果。
 * @tel 13001321080
 * @email 823436512@qq.com
 * @date 2021-04-30 9:03
 */
public class Code2 {
    public static void main(String[] args) {
        System.out.println(reverseBits(0b11100));
    }

    public static int reverseBits(int n) {
        int ans = 0;
        for (int i = 0; i < 32; i++) {
            ans += (n & (1 << 32 - i - 1)) == 0 ? 0 : 1 << i;
        }
        return ans;
    }
}
